package com.zhonghui.license;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;

public abstract class JsonUtil
{
    private static final Logger log;
    private static ObjectMapper mapper;
    
    public static String toJson(final Object obj) {
        try {
            if (obj != null) {
                return JsonUtil.mapper.writeValueAsString(obj);
            }
        }
        catch (JsonProcessingException e) {
            JsonUtil.log.error("JsonUtil fromJson toJson error ,msg {}", (Throwable)e);
        }
        return "";
    }
    
    public static <T> T fromJson(final String jsonStr, final Class<T> clzs) {
        try {
            return (T)JsonUtil.mapper.readValue(jsonStr, (Class)clzs);
        }
        catch (JsonProcessingException e) {
            JsonUtil.log.error("JsonUtil fromJson clzs error ,msg {}", (Throwable)e);
        }
        catch (IOException e2) {
            e2.printStackTrace();
        }
        return null;
    }
    
    public static <T> T fromJson(final String jsonStr, final TypeReference<T> valueTypeRef) {
        try {
            return (T)JsonUtil.mapper.readValue(jsonStr, (TypeReference)valueTypeRef);
        }
        catch (JsonProcessingException e) {
            JsonUtil.log.error("JsonUtil fromJson valueTypeRef  error,msg {}", (Throwable)e);
        }
        catch (IOException e2) {
            e2.printStackTrace();
        }
        return null;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)JsonUtil.class);
        (JsonUtil.mapper = new ObjectMapper()).disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, new DeserializationFeature[] { DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES });
        JsonUtil.mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        JsonUtil.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        JsonUtil.mapper.setDateFormat((DateFormat)new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    }
}
